home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / pibt3sp3.arc / PIBTIMER.PAS < prev    next >
Pascal/Delphi Source File  |  1985-09-07  |  16KB  |  322 lines

  1. (*--------------------------------------------------------------------------*)
  2. (*      TimeOfDayH  --- Get time of day in 1/100 seconds from midnight      *)
  3. (*--------------------------------------------------------------------------*)
  4.  
  5. FUNCTION TimeOfDayH : REAL;
  6.  
  7. (*--------------------------------------------------------------------------*)
  8. (*                                                                          *)
  9. (*     Function:  TimeOfDayH                                                *)
  10. (*                                                                          *)
  11. (*     Purpose:   Gets time of day from internal clock in 1/100 seconds     *)
  12. (*                                                                          *)
  13. (*     Calling sequence:                                                    *)
  14. (*                                                                          *)
  15. (*        Tod := TimeOfDayH : REAL;                                         *)
  16. (*                                                                          *)
  17. (*           Tod --- Real number which is timer value expressed in          *)
  18. (*                   hundredths of seconds as:                              *)
  19. (*                   ( 360000 x hour + 6000 x minutes + 100 x seconds +     *)
  20. (*                     hundredths of seconds ).                             *)
  21. (*                                                                          *)
  22. (*     Calls:  INTR                                                         *)
  23. (*                                                                          *)
  24. (*--------------------------------------------------------------------------*)
  25.  
  26. VAR
  27.    Regs:  RegPack;
  28.  
  29. BEGIN (* TimeOfDayH *)
  30.                                    (* Time of day interrupt *)
  31.    Regs.Ax := $2C00;
  32.    INTR( $21 , Regs );
  33.                                    (* Convert to hundredths of seconds *)
  34.                                    (* from 12AM                        *)
  35.    WITH Regs DO
  36.       TimeOfDayH  := Ch * 360000.0 + Cl * 6000.0 + Dh * 100.0 + Dl;
  37.  
  38. END   (* TimeOfDayH *);
  39.  
  40. (*--------------------------------------------------------------------------*)
  41. (*       TimeDiffH  --- Get difference in time between two timer values     *)
  42. (*--------------------------------------------------------------------------*)
  43.  
  44. FUNCTION TimeDiffH( Timer1, Timer2: REAL ) : REAL;
  45.  
  46. (*--------------------------------------------------------------------------*)
  47. (*                                                                          *)
  48. (*     Function:  TimeDiffH                                                 *)
  49. (*                                                                          *)
  50. (*     Purpose:   Get difference in time between two timer values           *)
  51. (*                in hundredths of seconds.                                 *)
  52. (*                                                                          *)
  53. (*     Calling sequence:                                                    *)
  54. (*                                                                          *)
  55. (*        Tdiff := TimeDiffH( Timer1, Timer2: REAL ) : REAL;                *)
  56. (*                                                                          *)
  57. (*           Timer1  --- first timer value (earlier)                        *)
  58. (*           Timer2  --- second timer value (later)                         *)
  59. (*                                                                          *)
  60. (*           Tdiff   --- difference between timer values                    *)
  61. (*                                                                          *)
  62. (*     Calls:  None                                                         *)
  63. (*                                                                          *)
  64. (*     Remarks:                                                             *)
  65. (*                                                                          *)
  66. (*        This routine will handle time wrap around midnight.  However, it  *)
  67. (*        only handles timer values <= 24 hours in duration.                *)
  68. (*                                                                          *)
  69. (*--------------------------------------------------------------------------*)
  70.  
  71. CONST
  72.    Hundredths_Secs_Per_Day = 8640000.0  (* 1/100 Seconds in one day *);
  73.  
  74. VAR
  75.    TDiff : REAL;
  76.  
  77. BEGIN (* TimeDiffH *)
  78.  
  79.    TDiff := Timer2 - Timer1;
  80.  
  81.    IF Tdiff < 0.0 THEN Tdiff := Tdiff + Hundredths_Secs_Per_Day;
  82.  
  83.    TimeDiffH := Tdiff;
  84.  
  85. END   (* TimeDiffH *);
  86.  
  87. (*--------------------------------------------------------------------------*)
  88. (*      TimeStringH  --- convert timer value in 1/100 secs to string        *)
  89. (*--------------------------------------------------------------------------*)
  90.  
  91. FUNCTION TimeStringH( Timer_Value : REAL ) : AnyStr;
  92.  
  93. (*--------------------------------------------------------------------------*)
  94. (*                                                                          *)
  95. (*     Function:  TimeStringH                                               *)
  96. (*                                                                          *)
  97. (*     Purpose:   Convert elapsed timer value to HH:MM:SS string            *)
  98. (*                                                                          *)
  99. (*     Calling sequence:                                                    *)
  100. (*                                                                          *)
  101. (*        Tstring := TimeStringH( Timer_Value : REAL ) : AnyStr;            *)
  102. (*                                                                          *)
  103. (*           Timer_Value --- Real number which is timer value expressed as  *)
  104. (*                           1/100 seconds from 12 am.                      *)
  105. (*           Tstring     --- Resultant 'HH:MM:SS' form of time              *)
  106. (*                                                                          *)
  107. (*     Calls:  None                                                         *)
  108. (*                                                                          *)
  109. (*--------------------------------------------------------------------------*)
  110.  
  111. VAR
  112.    Hours:    INTEGER;
  113.    Minutes:  INTEGER;
  114.    Seconds:  INTEGER;
  115.    Save_H:   REAL;
  116.    SH:       STRING[2];
  117.    SM:       STRING[2];
  118.    SS:       STRING[2];
  119.  
  120. BEGIN (* TimeStringH *)
  121.  
  122.    Timer_Value := INT( Timer_Value / 100.0 );
  123.  
  124.    Hours   := TRUNC( Timer_Value / 3600.0 );
  125.    Save_H  := Timer_Value - Hours * 3600.0;
  126.    Minutes := TRUNC( Save_H / 60.0 );
  127.    Seconds := TRUNC( Save_H - Minutes * 60.0 );
  128.  
  129.    STR( Hours:2,   SH );
  130.    STR( Minutes:2, SM );
  131.    STR( Seconds:2, SS );
  132.  
  133.    IF SH[1] = ' ' THEN SH[1] := '0';
  134.    IF SM[1] = ' ' THEN SM[1] := '0';
  135.    IF SS[1] = ' ' THEN SS[1] := '0';
  136.  
  137.    TimeStringH := SH + ':' + SM + ':' + SS;
  138.  
  139. END   (* TimeStringH *);
  140.  
  141. (*--------------------------------------------------------------------------*)
  142. (*                TimeOfDay  --- Get time of day                            *)
  143. (*--------------------------------------------------------------------------*)
  144.  
  145. FUNCTION TimeOfDay : REAL;
  146.  
  147. (*--------------------------------------------------------------------------*)
  148. (*                                                                          *)
  149. (*     Function:  TimeOfDay                                                 *)
  150. (*                                                                          *)
  151. (*     Purpose:   Gets time of day from internal clock                      *)
  152. (*                                                                          *)
  153. (*     Calling sequence:                                                    *)
  154. (*                                                                          *)
  155. (*        Tod := TimeOfDay : REAL;                                          *)
  156. (*                                                                          *)
  157. (*           Tod --- Real number which is timer value expressed in          *)
  158. (*                   seconds as:                                            *)
  159. (*                   ( 3600 x hour + 60 x minutes + seconds )               *)
  160. (*                                                                          *)
  161. (*     Calls:  INTR                                                         *)
  162. (*                                                                          *)
  163. (*--------------------------------------------------------------------------*)
  164.  
  165. VAR
  166.    Regs:  RegPack;
  167.  
  168. BEGIN (* TimeOfDay *)
  169.                                    (* Time of day interrupt *)
  170.    Regs.Ax := $2C00;
  171.    INTR( $21 , Regs );
  172.                                    (* Convert to number of seconds since *)
  173.                                    (* 12AM                               *)
  174.    WITH Regs DO
  175.       TimeOfDay  := Ch * 3600.0 + Cl * 60.0 + Dh;
  176.  
  177. END   (* TimeOfDay *);
  178.  
  179. (*--------------------------------------------------------------------------*)
  180. (*        TimeDiff  --- Get difference in time between two timer values     *)
  181. (*--------------------------------------------------------------------------*)
  182.  
  183. FUNCTION TimeDiff( Timer1, Timer2: REAL ) : REAL;
  184.  
  185. (*--------------------------------------------------------------------------*)
  186. (*                                                                          *)
  187. (*     Function:  TimeDiff                                                  *)
  188. (*                                                                          *)
  189. (*     Purpose:   Get difference in time between two timer values in        *)
  190. (*                seconds.                                                  *)
  191. (*                                                                          *)
  192. (*     Calling sequence:                                                    *)
  193. (*                                                                          *)
  194. (*        Tdiff := TimeDiff( Timer1, Timer2: REAL ) : REAL;                 *)
  195. (*                                                                          *)
  196. (*           Timer1  --- first timer value (earlier)                        *)
  197. (*           Timer2  --- second timer value (later)                         *)
  198. (*                                                                          *)
  199. (*           Tdiff   --- difference between timer values                    *)
  200. (*                                                                          *)
  201. (*     Calls:  None                                                         *)
  202. (*                                                                          *)
  203. (*     Remarks:                                                             *)
  204. (*                                                                          *)
  205. (*        This routine will handle time wrap around midnight.  However, it  *)
  206. (*        only handles timer values <= 24 hours in duration.                *)
  207. (*                                                                          *)
  208. (*--------------------------------------------------------------------------*)
  209.  
  210. CONST
  211.    Secs_Per_Day = 86400.0  (* Seconds in one day *);
  212.  
  213. VAR
  214.    TDiff : REAL;
  215.  
  216. BEGIN (* TimeDiff *)
  217.  
  218.    TDiff := Timer2 - Timer1;
  219.  
  220.    IF Tdiff < 0.0 THEN Tdiff := Tdiff + Secs_Per_Day;
  221.  
  222.    TimeDiff := Tdiff;
  223.  
  224. END   (* TimeDiff *);
  225.  
  226. (*--------------------------------------------------------------------------*)
  227. (*          TimeString  --- convert timer value to string                   *)
  228. (*--------------------------------------------------------------------------*)
  229.  
  230. FUNCTION TimeString( Timer_Value : REAL ) : AnyStr;
  231.  
  232. (*--------------------------------------------------------------------------*)
  233. (*                                                                          *)
  234. (*     Function:  TimeString                                                *)
  235. (*                                                                          *)
  236. (*     Purpose:   Convert elapsed timer value to HH:MM:SS string            *)
  237. (*                                                                          *)
  238. (*     Calling sequence:                                                    *)
  239. (*                                                                          *)
  240. (*        Tstring := TimeString( Timer_Value : REAL ) : AnyStr;             *)
  241. (*                                                                          *)
  242. (*           Timer_Value --- Real number which is timer value expressed as  *)
  243. (*                           seconds from 12 am.                            *)
  244. (*           Tstring     --- Resultant 'HH:MM:SS' form of time              *)
  245. (*                                                                          *)
  246. (*     Calls:  None                                                         *)
  247. (*                                                                          *)
  248. (*--------------------------------------------------------------------------*)
  249.  
  250. VAR
  251.    Hours:    INTEGER;
  252.    Minutes:  INTEGER;
  253.    Seconds:  INTEGER;
  254.    Save_H:   REAL;
  255.    SH:       STRING[2];
  256.    SM:       STRING[2];
  257.    SS:       STRING[2];
  258.  
  259. BEGIN (* TimeString *)
  260.  
  261.    Hours   := TRUNC( Timer_Value / 3600.0 );
  262.    Save_H  := Timer_Value - Hours * 3600.0;
  263.    Minutes := TRUNC( Save_H / 60.0 );
  264.    Seconds := TRUNC( Save_H - Minutes * 60.0 );
  265.  
  266.    STR( Hours:2,   SH );
  267.    STR( Minutes:2, SM );
  268.    STR( Seconds:2, SS );
  269.  
  270.    IF SH[1] = ' ' THEN SH[1] := '0';
  271.    IF SM[1] = ' ' THEN SM[1] := '0';
  272.    IF SS[1] = ' ' THEN SS[1] := '0';
  273.  
  274.    TimeString := SH + ':' + SM + ':' + SS;
  275.  
  276. END   (* TimeString *);
  277.  
  278. (*--------------------------------------------------------------------------*)
  279. (*          DateString  --- Return current date in MM/DD/YY form            *)
  280. (*--------------------------------------------------------------------------*)
  281.  
  282. FUNCTION DateString: AnyStr;
  283.  
  284. (*--------------------------------------------------------------------------*)
  285. (*                                                                          *)
  286. (*     Function:  DateString                                                *)
  287. (*                                                                          *)
  288. (*     Purpose:   Returns current date in MM/DD/YY form                     *)
  289. (*                                                                          *)
  290. (*     Calling sequence:                                                    *)
  291. (*                                                                          *)
  292. (*        Dstring := DateString: AnyStr;                                    *)
  293. (*                                                                          *)
  294. (*           Dstring     --- Resultant 'MM/DD/YY' form of date              *)
  295. (*                                                                          *)
  296. (*     Calls:  MsDos                                                        *)
  297. (*                                                                          *)
  298. (*--------------------------------------------------------------------------*)
  299.  
  300. VAR
  301.   RecPack:       regpack;
  302.   Month:         STRING[2];
  303.   Day:           STRING[2];
  304.   Year:          STRING[4];
  305.  
  306. BEGIN (* DateString *)
  307.                                    (* Date function *)
  308.   RecPack.Ax := $2A00;
  309.                                    (* Get date from DOS *)
  310.   MsDos( RecPack );
  311.                                    (* Convert to MM/DD/YY string *)
  312.   WITH Recpack DO
  313.      BEGIN
  314.         STR( Cx         , Year  );
  315.         STR( Dx MOD 256 , Day   );
  316.         STR( Dx SHR 8   , Month );
  317.      END;
  318.  
  319.   DateString := Month + '/' + Day + '/' + Year;
  320.  
  321. END   (* DateString *);
  322.